package wjx.database.jdbc;

import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.ResultSet;
import java.sql.Statement;

//实现与数据库的连接
public class JDBC {
	static final String DRIVER = "com.mysql.cj.jdbc.Driver" ;
	static final String DB = "jdbc:mysql://localhost:3306/?useSSL=false&serverTimezone=UTC" ;
	
	//database auth
	static final String USER = "root" ;
	static final String PASSWORD = "wang19991107" ;
	
	public static void main(String[] args) {
		
		try {
			//加载驱动
			Class.forName(DRIVER) ;
			System.out.println("驱动加载成功");
			//连接数据库
			Connection conn = DriverManager.getConnection(DB,USER,PASSWORD); 
			System.out.println("数据库连接成功");
			//创建执行环境
			Statement statement = conn.createStatement() ;
			//执行sql语句,得到结果集
			ResultSet result = statement.executeQuery("select * from databaseManager.adultdata") ;
//			while(result.next()) {
//				System.out.println(result.getInt("age")) ;
//			}		
		} catch (Exception e) {
			e.printStackTrace();
			System.out.println("数据库连接失败");
		}
	}
}
